<!DOCTYPE html>
<html lang="en">

	<head>

		<meta charset="utf-8" />

		<title></title>

		<!-- IE -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!-- 设置 viewport -->
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- 兼容国产浏览器的高速模式 -->
		<meta name="renderer" content="webkit">
		<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->

		<!-- BEGIN 全局样式 -->
		<link rel="stylesheet" type="text/css" href="../../css/reset.css" />
		<link href="../../lib/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="../../css/common.css" />

		<link rel="stylesheet" type="text/css" href="../../lib/bootstrapvalidator/dist/css/bootstrapValidator.css" />
		<!-- END 全局样式 -->
		<style type="text/css">

		</style>
	</head>

	<!-- END HEAD -->

	<!-- BEGIN BODY -->

	<body class="">
		<div class="container-fluid mt-15">
			<form class="form " id="form">
				<div class="form-group">
					<label for="mac">mac识别码</label>
					<input type="text" class="form-control" id="mac" placeholder="请输入mac识别码" name="mac">
				</div>
				<div class="form-group">
					<label for="version">版本号</label>
					<input type="text" class="form-control" id="version" placeholder="请输入版本号" name="version">
				</div>
				
				<div class="form-group">
					<label for="address">部署详细地址</label>
					<input type="text" class="form-control" id="address" placeholder="请输入部署详细地址" name="address">
				</div>
				<div class="form-group">
					<label for="roleList">分组</label>
					<select class="form-control" id="group" name="group">
						<option value="1">大门</option>
						<option value="2">教室</option>
						<option value="3">操场</option>
					</select>
				</div>

				<div class="form-group">
					<label for="workState">工作状态</label>
					<select class="form-control" id="workState" name="workState">
						<option value="1">正常</option>
						<option value="2">异常</option>
					</select>
				</div>
				<div class="form-group">
					<label for="connectState">连接状态</label>
					<select class="form-control" id="connectState" name="connectState">
						<option value="1">在线</option>
						<option value="2">离线</option>
					</select>
				</div>
				<div>
					<button type="button" class="btn btn-success btn-save">
					  	<span class="glyphicon glyphicon-floppy-saved"></span>
					  	保存
				 	 </button>
					<button type="reset" class="btn btn-warning btn-reset">
			  			<span class="glyphicon glyphicon-record"></span>
			  			取消
			  		</button>
				</div>

			</form>
		</div>

		<!--核心脚本sss-->
		<script src="../../lib/jquery/1.9.1/jquery.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../lib/layer/2.4/layer.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../lib/laypage/1.2/laypage.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../lib/bootstrap-3.3.7-dist/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>

		<script src="../../js/common/jsrsasign-all-min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/common/crypto-js.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/common/jquery.myPlugIn_v1.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/common/localstorage-ie.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../lib/bootstrapvalidator/dist/js/bootstrapValidator.js" type="text/javascript" charset="utf-8"></script>
		
		<!--公共脚本-->
		<script src="../../js/common/common.js" type="text/javascript" charset="utf-8"></script>
		<!--[if lt IE 9]>
		<script src="../../js/excanvas.min.js"></script>
		<script src="../../js/respond.min.js"></script>  
		<![endif]-->
		<!--核心脚本eee-->

		<script type="text/javascript">
			$(document).ready(function() {
				
				
				
				
				
				//初始化表单验证
				$('#form')
					.bootstrapValidator({
						message: '这个值是无效的',
						feedbackIcons: {
							valid: 'glyphicon glyphicon-ok',
							invalid: 'glyphicon glyphicon-remove',
							validating: 'glyphicon glyphicon-refresh'
						},
						fields: {
							mac:{
								notEmpty: {
									message: 'mac识别码是必需的，不能是空的'
								},								
							},
							version:{
								notEmpty: {
									message: '版本号是必需的，不能是空的'
								},								
							},
							address: {
								validators: {
									notEmpty: {
										message: '地址是必需的，不能是空的'
									},
									stringLength: {
										min: 10,
										max: 50,
										message: '地址必须大于10，小于50个字符'
									},
									
								}
							},
							
				            
						}
					})
					.on('success.form.bv', function(e) {
						// 阻止表单提交
						e.preventDefault();
						//添加
						if(localStorage.getItem("optionType") == "add") {
							// 获得表单实例
							var $form = $(e.target);
							fnAjax.method_4(
								url_join("device/create"),
								$.serializeToObj($form.serialize()),	
								"post",
								function(data) {
									console.log(data);
									layer.msg("操作成功", {
										time: 1500
									}, function() {
										parent.location.reload();
									});
								}
							);
						}
						//更新
						else {
							$('#form').append($('<input type="hidden" value="' + localStorage.getItem("nId") + '" name="uid"/>'));
							var $form = $(e.target);
							fnAjax.method_4(
								url_join("device/update"),
								$.serializeToObj($form.serialize()),
								"post",
								function(data) {
									console.log(data);
									layer.msg("操作成功", {
										time: 1500
									}, function() {
										parent.location.reload();
									});
								}
							);
						}

					});
				// 手动验证表单
				$('.btn-save').click(function() {
					$('#form').bootstrapValidator('validate');
				});

			});
		</script>
	</body>

</html>